﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyBatis.Data.Contract;
using MyBatis.Data.Model;
using MyBatis.Data.Service;

namespace MyBatisDemo
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindData(true);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.BindData(true);
        }

        private void BindData(bool isReset)
        {
            ICustomersService service=new CustomersService();
            CustomersQP custQp = new CustomersQP();
            if (!string.IsNullOrEmpty(txtContactName.Text))
            {
                custQp.ContactName = txtContactName.Text.Trim();
            }
            if (!string.IsNullOrEmpty(txtAddress.Text))
            {
                custQp.Address = txtAddress.Text.Trim();
            }
            custQp.PageSize = this.dataPager.PageSize;
            if (isReset)
            {
                custQp.PageIndex = this.dataPager.CurrentPageIndex;
            }
            IList<Customers> list = service.GetCustomerss(custQp);
            this.dataPager.RecordCount = custQp.ItemCount;
            this.rptDataList.DataSource = list;
            this.rptDataList.DataBind();
        }

        protected void dataPager_PageChanged(object sender, EventArgs e)
        {
            this.BindData(false);
        }
    }
}